﻿@using Xproject.Util;
@{
    Layout = null;
    string Domain = CommonHelper.GetAppSettings("Domin");
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    @*1、Jquery组件引用*@
    <script src="~/Scripts/jquery-1.10.2.js"></script>

    @*2、bootstrap组件引用*@

    <script src="~/Scripts/bootstrap.js"></script>
    <link href="~/Content/bootstrap.css" rel="stylesheet" />

    @*3、bootstrap table组件以及中文包的引用*@
    <script src="~/Content/bootstrap-table/bootstrap-table.js"></script>
    <link href="~/Content/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
    <script src="~/Content/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script src="~/Scripts/layer/layer.js"></script>
    @*4、页面Js文件的引用*@
    <script type="text/javascript">

        $(function () {

            //1.初始化Table
            var oTable = new TableInit();
            oTable.Init();

            //2.初始化Button的点击事件
            var oButtonInit = new ButtonInit();
            oButtonInit.Init();

            $("#btn_query").click(function () {
                $("#tb_rolelist").bootstrapTable('refresh');
            });
        });


        var TableInit = function () {
            var oTableInit = new Object();
            //初始化Table
            oTableInit.Init = function () {
                $('#tb_rolelist').bootstrapTable({
                    url: '/system/GetRoleList',         //请求后台的URL（*）
                    method: 'get',                      //请求方式（*）
                    toolbar: '#toolbar',                //工具按钮用哪个容器
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    sortable: true,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: oTableInit.queryParams,//传递参数（*）
                    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                       //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                    search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    strictSearch: true,
                    showColumns: true,                  //是否显示所有的列
                    showRefresh: true,                  //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    clickToSelect: true,                //是否启用点击选中行
                    height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                    showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                    cardView: false,                    //是否显示详细视图
                    detailView: false,                   //是否显示父子表
                    columns: [
                            {
                            checkbox: true
                            },
                            {
                                field: 'RoleName',
                            title: '角色名'
                            },
                            {
                                field: 'RoleDesc',
                                title: '角色描述'
                            }   ,
                            {
                                field: 'RoleIcon',
                            title: '图标'
                            },
                            {
                                field: 'Enable',
                                title: '有效',
                                formatter: function (value, row, index) {
                                    var result = "";
                                    if (value == 1) {
                                        result = "有效";
                                    } else {
                                        result = "无效";
                                    }
                                    return result;
                                }
                            },
                            {
                                field: 'RoleId',
                                title: '操作',
                                align: 'center',
                                valign: 'middle',
                                formatter: actionFormatter,

                            },
                    ]
                });
            };

            //得到查询的参数
            oTableInit.queryParams = function (params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,   //页面大小
                    offset: params.offset,  //页码
                    order: params.order,
                    ordername: params.sort,
                    roleName: $("#txt_search_rolename").val(),
                    roleDesc: $("#txt_search_roledesc").val()
                };
                return temp;
            };
            return oTableInit;
        };


        var ButtonInit = function () {
            var oInit = new Object();
            var postdata = {};

            oInit.Init = function () {
            };

            return oInit;
        };


        function AddNewRole() {
            layer.open({
                type: 2,
                title: '新增菜单',
                shadeClose: true,
                shade: 0.8,
                area: ['800px', '96%'],
                end: function (index) {
               //刷新页面
                    $("#tb_rolelist").bootstrapTable('refresh');
                },
                content: '@(Domain)/System/RoleEdit' //iframe的url
            });
        }

        function actionFormatter(value, row, index) {
            var id = value;
            var result = "";

            var rows = row;
            result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"EditAdminRole('" + id + "')\" title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
            result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"DelAdminRole('" + id + "')\" title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
            result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"RoleMenuEdit('" + id + "')\" title='角色菜单权限'>角色菜单权限 </a>";
            return result;
        }

        function RoleMenuEdit(id) {
            layer.open({
                type: 2,
                title: '编辑角色菜单',
                shadeClose: true,
                shade: 0.8,
                area: ['600px', '96%'],
                end: function (index) {
                },
                content: '@(Domain)/System/RoleMenuEdit' + "?roleId=" + id//iframe的url
            });
        }


        function DelAdminRole(roleId) {
            layer.confirm('确认删除此角色？', {
                btn: ['确认', '取消'] //按钮
            }, function () {

                    $.ajax({
                         url: "@(Domain+ "/system/DelAdminRole")",
                    type: 'post',
                    cache: 'false',
                    async: 'false',
                    data: { roleId: roleId },
                    success: function (data) {
                        if (data.Success == true) {
                            layer.alert('删除成功', { icon: 1, skin: 'layer-ext-moon', time: 2000 });
                            $("#tb_rolelist").bootstrapTable('refresh');
                        } else {
                            layer.alert('删除失败', { icon: 1, skin: 'layer-ext-moon', time: 2000 });
                        }
                           },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {

                        }
                    });


                }, function () {
                    layer.closeAll('dialog');
                }
               );

        }

        function EditAdminRole(id) {
            layer.open({
                type: 2,
                title: '编辑角色',
                shadeClose: true,
                shade: 0.8,
                area: ['800px', '96%'],
                end: function (index) {
                    //刷新页面
                    $("#tb_rolelist").bootstrapTable('refresh');
                },
                content: '@(Domain)/System/RoleEdit' + "?roleId=" + id//iframe的url
            });
        }

    </script>
</head>
<body>
    <div class="panel-body" style="padding-bottom:0px;">
        <div class="panel panel-default">
            <div class="panel-heading">查询条件</div>
            <div class="panel-body">
                <form id="formSearch" class="form-horizontal">
                    <div class="form-group" style="margin-top:15px">
                        <label class="control-label col-sm-1" for="txt_search_rolename">角色名称</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="txt_search_rolename">
                        </div>
                        <label class="control-label col-sm-1" for="txt_search_roledesc">角色描述</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="txt_search_roledesc">
                        </div>
                        <div class="col-sm-4" style="text-align:left;">
                            <button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary">查询</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <div id="toolbar" class="btn-group">
            <button id="btn_add" type="button" class="btn btn-default" onclick="AddNewRole();">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增角色
            </button>
        </div>
        <table id="tb_rolelist"></table>
    </div>
</body>
</html>
